const Utils = require('./../utils/utils');

class Cluster {
  constructor (dao) {
    this.dao = dao;
  }
  queryAll (params) {
    return this.dao.queryAll(params).then(result => {
      return {
        data: result
      };
    }).catch(reason => {
      return reason;
    });
  }
  query (params) {
    params = Utils.mergeObject({}, Utils.defaultQueryParameter, params);
    return Promise.all([this.dao.query(params), this.dao.count()])
      .then(result => {
        return {
          data: result[0],
          total: result[1][0].total
        };
      }).catch(reason => {
        return reason;
      });
  }

  delete (params) {
    return this.dao.delete(params).then(result => {
      return result;
    }).catch(reason => {
      return reason;
    });
  }

  expunge (params) {
    return this.dao.expunge(params).then(result => {
      return result;
    }).catch(reason => {
      return reason;
    });
  }

}

module.exports = Cluster;
